package com.QiLin.controller;

import com.QiLin.domain.letters;
import com.QiLin.service.LetterService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class Letter {
    @Resource
    private LetterService letterService;

    @RequestMapping("/Send.do")
    public String Send(letters letters, HttpSession httpSession)throws Exception{
        if(letters.getHeadline().length()<=10){
            boolean booDetection= letterService.SendDetection(letters.getReceiveUser(),httpSession.getAttribute("user")+letters.getHeadline());
            if(booDetection){
                boolean boo= letterService.SendService(letters,httpSession);
                if(boo==true){
                    return "/Mailbox";
                }else{
                    return "/test2";
                }
            }else{
                return "/test3";
            }
        }else{
            return "/test3";
        }
    }

    @RequestMapping("/Updates.do")
    @ResponseBody
    public List<letters> Updates(HttpSession session){
       List<letters> le= letterService.UpdatesService(session);
        return le;
    }

    @RequestMapping("/Article")
    @ResponseBody
    public List<String> Article(HttpSession session){
        return (List<String>) session.getAttribute("liststring");
    }

}
